package com.m.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class AspectDemo {
    @Pointcut("execution(* com.m.demo.controller.*.*(..))")
//    private void pt(){}
    public void pt(){}

    @Before("pt()")
    public void doBefore(){
        log.info("执行AspectDemo before...");
    }

    @After("pt()")
    public void doAfter(){
        log.info("执行AspectDemo after...");
    }

    @AfterReturning("pt()")
    public void doAfterReturn(){
        log.info("执行AspectDemo afterReturn...");
    }

    @AfterThrowing("execution(* com.m.demo.controller.*.*(..))")
    public void doAfterThrow(){
        log.info("执行AspectDemo afterThrow...");
    }

    @Around("execution(* com.m.demo.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable{
        log.info("执行AspectDemo doAround前...");
        Object result = pjp.proceed();
        log.info("执行AspectDemo doAround后...");
        return result;
    }
}
